package com.example.spingbootvue.service;

import com.example.spingbootvue.entity.User;
import com.example.spingbootvue.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class registerservice {

    @Autowired
    UserMapper userMapper;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    public int  register(User user,String usercode){

        //从redis取出验证码
        String code = redisTemplate.opsForValue().get(user.getEmail());

        User ts=userMapper.findbyaccount(user.getAccount(),user.getEmail());
         if(ts!=null){
             return -2;//账号和邮箱重复
         }else if(!usercode.equals(code)){
             return -1;//-1验证码错误
         }else{
             return userMapper.insertAll(user.getAccount(),user.getPassword(),user.getPosition(),user.getEmail());
         }
    }

}
